package com.sskj.run.http;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.App;
import com.sskj.common.base.HttpData;
import com.sskj.common.http.WebSocketObserver;
import com.sskj.common.util.LanguageUtil;
import com.sskj.lib.Constans;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.util.CommonUtil;
import com.sskj.run.bean.AssetAllNewBean;
import com.sskj.run.bean.AssetBean;
import com.sskj.run.bean.BankerHistoryBean;
import com.sskj.run.bean.BankersMainBean;
import com.sskj.run.bean.BillRecordBean;
import com.sskj.run.bean.CoinTypeBean;
import com.sskj.run.bean.CommonBean;
import com.sskj.run.bean.ExchangeUsable;
import com.sskj.run.bean.FaqBean;
import com.sskj.run.bean.MyGuessBean;
import com.sskj.run.bean.OpenAwardBean;
import com.sskj.run.bean.RankBean;
import com.sskj.run.bean.RechargeBean;
import com.sskj.run.bean.SocketSendBean;
import com.sskj.run.bean.ToRechargeBean;
import com.sskj.run.bean.VcerifyBean;
import com.sskj.run.bean.ZhanjiBean;

import java.util.List;
import java.util.Locale;

import okhttp3.WebSocket;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {


    public PostRequest<HttpData<CommonBean>> getCommonData() {
        return OkGo.<HttpData<CommonBean>>post(HttpConfig.BASE_URL + HttpConfig.COMMON_DATA);
    }


    public PostRequest<HttpData<PageBean<RankBean>>> rankList(String money_type, String type, int page, int size) {
        return OkGo.<HttpData<PageBean<RankBean>>>post(HttpConfig.BASE_URL + HttpConfig.RANK_LIST)
                .params("money_type", money_type.toLowerCase())
                .params("type", type)
                .params("page", page)
                .params("size", size);
    }


    public PostRequest<HttpData<PageBean<BillRecordBean>>> billRecordList(String money_type, String start_time, String end_time, int page, int size) {
        return OkGo.<HttpData<PageBean<BillRecordBean>>>post(HttpConfig.BASE_URL + HttpConfig.BILL_LIST)
                .params("money_type", money_type.toLowerCase())
                .params("start_time", start_time)
                .params("end_time", end_time)
                .params("page", page)
                .params("size", size);
    }


    public PostRequest<HttpData<PageBean<OpenAwardBean>>> openAwardList(int page, int size) {
        return OkGo.<HttpData<PageBean<OpenAwardBean>>>post(HttpConfig.BASE_URL + HttpConfig.OPEN_AWARD)
                .params("page", page)
                .params("size", size);
    }


    public PostRequest<HttpData<PageBean<MyGuessBean>>> myGuessList(int page, int size) {
        return OkGo.<HttpData<PageBean<MyGuessBean>>>post(HttpConfig.BASE_URL + HttpConfig.MY_GUESS)
                .params("page", page)
                .params("size", size);
    }


    public PostRequest<HttpData<BankersMainBean>> bankerPoolMain(String money_type) {
        return OkGo.<HttpData<BankersMainBean>>post(HttpConfig.BASE_URL + HttpConfig.BANKER_POLL_MAIN)
                .params("money_type", money_type.toLowerCase());
    }


    public PostRequest<HttpData<PageBean<BankerHistoryBean>>> bankerPoolHistory(String money_type, int page, int size) {
        return OkGo.<HttpData<PageBean<BankerHistoryBean>>>post(HttpConfig.BASE_URL + HttpConfig.BANKER_POLL_HISTORY)
                .params("money_type", money_type.toLowerCase())
                .params("page", page)
                .params("size", size);
    }


    public PostRequest<HttpData> bankerInOut(String money_type, String money) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BANKER_IN_OUT)
                .params("money_type", money_type.toLowerCase())
                .params("money", money);
    }


    public PostRequest<HttpData> normalBet(String money_type, String money, String escape_beishu) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.NOEMAL_BET)
                .params("type", money_type.toLowerCase())
                .params("money", money)
                .params("escape_beishu", escape_beishu);
    }


    public PostRequest<HttpData> normalRun() {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.NOEMAL_RUN);
    }


    public PostRequest<HttpData<PageBean<VcerifyBean>>> vcerify(String hash, String num) {
        return OkGo.<HttpData<PageBean<VcerifyBean>>>post(HttpConfig.BASE_URL + HttpConfig.VERIFY)
                .params("hash", hash)
                .params("num", num);
    }


    public PostRequest<HttpData<ToRechargeBean>> getRechargeUrl(String price) {
        return OkGo.<HttpData<ToRechargeBean>>post(HttpConfig.BASE_URL + HttpConfig.CHONGZHI)
                .params("pay_type", 1)
                .params("orderamount", price);
    }


    public PostRequest<HttpData<ToRechargeBean>> getCoinRechargeUrl(String price, int type) {
        return OkGo.<HttpData<ToRechargeBean>>post(HttpConfig.BASE_URL + HttpConfig.COIN_CHONGZHI)
                .params("pid", 3)
                .params("pay_type", type)
                .params("orderamount", price);
    }


    public WebSocketObserver pushBloomType(String type) {
        return new WebSocketObserver(HttpConfig.WS_BOOM_URL) {

            public void onOpen(WebSocket webSocket, okhttp3.Response response, String msg) {
                if (TextUtils.isEmpty(msg)) {
                    webSocket.send(new Gson().toJson(new SocketSendBean(Constans.DEFAULT_BIBI_COIN)));
                }else {
                    webSocket.send(msg);
                }
            }
        };
    }

    public PostRequest<HttpData<List<FaqBean>>> getFAQ() {
        return OkGo.<HttpData<List<FaqBean>>>post(HttpConfig.BASE_URL + HttpConfig.RUN_FAQ)
                .params("type", (LanguageUtil.getAppLocale(App.INSTANCE) == Locale.ENGLISH) ? "2" : "1")
                ;

    }


    public PostRequest<HttpData<ZhanjiBean>> getZhanji(String money_type) {
        return OkGo.<HttpData<ZhanjiBean>>post(HttpConfig.BASE_URL + HttpConfig.RUN_ZHANJI)
                .params("money_type", money_type.toLowerCase())
                ;

    }


    public PostRequest<HttpData<List<AssetBean>>> getAsset() {
        return OkGo.<HttpData<List<AssetBean>>>post(HttpConfig.BASE_URL + HttpConfig.RUN_ASSET);

    }


    public PostRequest<HttpData> recharge(boolean isIn, String money_type, String num, String pwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + (isIn ? HttpConfig.RUN_EXCHNAGE_IN : HttpConfig.RUN_EXCHNAGE_OUT))
                .params("currency", money_type.toLowerCase())
                .params("price", num)
                .params("pwd", pwd)
                ;
    }

    public PostRequest<HttpData<List<CoinTypeBean>>> getCoinType() {
        return OkGo.<HttpData<List<CoinTypeBean>>>post(HttpConfig.BASE_URL + HttpConfig.RUN_COIN_TYPE)
                ;
    }
    public PostRequest<HttpData> exchange(String formWalletType,String toWalletType,String rotationNum,String payment_password,String id) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.EXCHANGE)
                .params("formWalletType", formWalletType)
                .params("toWalletType", toWalletType)
                .params("rotationNum", rotationNum)
                .params("payment_password", CommonUtil.getFiveMd5Value(payment_password))
                .params("id", id)
                ;
    }
    public PostRequest<HttpData<ExchangeUsable>> getExchangeUsable(String formWalletType, String id) {
        return OkGo.<HttpData<ExchangeUsable>>post(HttpConfig.BASE_URL + HttpConfig.GET_EXCHANGE_USABLE)
                .params("formWalletType", formWalletType)
                .params("id", id)
                ;
    }

}